//
//  LivePhotoViewController.swift
//  GifUsage
//
//  Created by han on 2021/1/5.
//  Copyright © 2021 Ting Han. All rights reserved.
//

import UIKit
import Photos
import PhotosUI

class LivePhotoViewController: UIViewController {
    
    @IBOutlet weak var livePhotoView: PHLivePhotoView!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        displayLocal()
    }
    
    @IBAction func generateLivePhotoAction(_ sender: Any) {
        self.livePhotoView.startPlayback(with: .full)
    }
    
    @IBAction func saveLocalAction(_ sender: Any) {
        
    }
    
    @IBAction func saveAlbumAction(_ sender: Any) {
        
    }
    
    func displayLocal() {
        let photoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "d88", ofType: "jpg")!)
        let movieURL = URL(fileURLWithPath: Bundle.main.path(forResource: "c82", ofType: "mov")!)
        
        PHLivePhoto.request(withResourceFileURLs: [photoURL, movieURL], placeholderImage: UIImage(named: "d87.jpeg"), targetSize: livePhotoView.frame.size, contentMode: .aspectFit) { (livePhoto, info) in
            self.livePhotoView.livePhoto = livePhoto
            self.livePhotoView.startPlayback(with: .full)
        }
    }
    
}
